use "$project_path/data/4_regdata/regdata", clear
merge m:1 Country Year using "$project_path/data/3_cleaned/outcomes", keep(master match) keepusing(const_event new_const_ext const_amend)

** Appendix Figure C.5(a)

rdrobust const_event runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot const_event runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C5a.pdf", as(pdf) name("Graph") replace

** Appendix Figure C.5(b)

rdrobust new_const_ext runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot new_const_ext runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C5b.pdf", as(pdf) name("Graph") replace

** Appendix Figure C.5(c)

rdrobust const_amend runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot const_amend runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C5c.pdf", as(pdf) name("Graph") replace

